The right Type in C#

The type of image it acts as an assembly, a module or a type. Fortunately, it is very easy to get the context of an object, because every class that is inherited from the object class, has the GetType () method. If you need information about a non-immediate type, then you can use globally available type () method, which should consider the following examples:

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ReflectionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string test = "test";
            Console.WriteLine(test.GetType().FullName);
            Console.WriteLine(typeof(Int32).FullName);
            Console.ReadKey();
        }
    }
}

We use the GetType () method on our variable, and then we use the type () of a known class, as you can see, in both cases, the result is a type of object, for which we have the full name Can read the property.

At some point, you may also have a type of name that you are looking for. In that case, you have to get a reference from the proper assembly. In the next example, we get reference to the execution assembly, i.e. the assembly from which the current code is being executed, and then we list all types of it:.

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ReflectionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Type[] assemblyTypes = assembly.GetTypes();
            foreach(Type t in assemblyTypes)
                Console.WriteLine(t.Name);
            Console.ReadKey();
        }
    }

    class DummyClass
    {
        //Just here to make the output a tad less boring :)
    }
}

Output will be the name of two declassified classes, programs and dummy class, but in more complex applications, the list will probably be more interesting. In this case, we only get this type of name, but obviously we can do much with type references. Will be enabled. In the next sections, I will tell you something else about what we can do with it.